package com.qiyu.dubbo.router.starter.protocol;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.RpcException;

/**
 * dubbo内部的aop实现
 *
 * @Author idea
 * @Date created in 11:45 下午 2020/11/26
 */
public class ZoneProtocolWrapper implements Protocol {

    private Protocol protocol;

    public ZoneProtocolWrapper(Protocol protocol) {
        this.protocol = protocol;
    }

    @Override
    public int getDefaultPort() {
        return protocol.getDefaultPort();
    }

    @Override
    public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
        URL url = invoker.getUrl();
        Object object = invoker;
        url = url.addParameter("version", "1.0.0");
        System.out.println(url);
        System.out.println("this is export");
        return protocol.export(invoker);
    }

    @Override
    public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
        return protocol.refer(type, url);
    }

    @Override
    public void destroy() {

    }
}
